
$(function(){
	//默认不同意
	$('.zhuce_mima #submit').css("background","gray");
	$("input[name='submit1']").attr("disabled","disabled");
	
	$("input[name='inlineCheckbox3']").click(function() {
		if(document.getElementById("inlineCheckbox3").checked){
			$("input[name='submit1']").removeAttr("disabled");
			$('.zhuce_mima #submit').css("background","#FF682F");
		}else{
			$("input[name='submit1']").attr("disabled","disabled");
			$('.zhuce_mima #submit').css("background","gray");
		}
	});
})
//添加
function subMsg() {

	var phone = $('#phone').val().trim();
	if(phone == '') {
		layer.alert("请输入手机号码！");
		return false;
	}
	var code = $('#code').val().trim();
	if(code == '') {
		layer.alert("请输入验证码！");
		return false;
	}

	var password = $('#password').val().trim();
	if(password == '') {
		layer.alert("请输入密码！");
		return false;
	}
	var repassword = $('#repassword').val().trim();
	if(repassword == '') {
		layer.alert("请再次输入密码！");
		return false;
	}
	if(password != repassword) {
		layer.alert("两次输入密码不一致！");
		return false;
	}
	var userName = $('#userName').val().trim();
	if(userName == '') {
		layer.alert("请输入昵称！");
		return false;
	}
	/*if(!$("input[type='checkbox']").is(':checked')) {
		alert("请先同意《佳港商城服务协议》！");
		return false;
	}*/
	$.ajax({
		url: urlcore + "/api/user/registerUser",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"userName": userName,
			"password": password,
			"repassword": repassword,
			"phone": phone,
			"code": code
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				if(confirm("添加成功！")) {
					//刷新
					//location.reload();
					window.location.href = "1.3.2zhuce_chenggong.html";
				} else {
					//跳转列表页
					window.location.href = "1.3.0zhuce.html";
				}
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				layer.alert(data.msg);
			}

		},
		error: function() {
			layer.alert("error");
		}

	});
}
function getPassword() {

	var phone = $('#phone').val().trim();
	if(phone == '') {
		alert("请输入手机号码！");
		return false;
	}
	var code = $('#code').val().trim();
	if(code == '') {
		alert("请输入验证码！");
		return false;
	}

	var password = $('#password').val().trim();
	if(password == '') {
		alert("请输入密码！");
		return false;
	}
	var repassword = $('#repassword').val().trim();
	if(repassword == '') {
		alert("请再次输入密码！");
		return false;
	}
	if(password != repassword) {
		alert("两次输入密码不一致！");
		return false;
	}
	
	
	$.ajax({
		url: urlcore + "/api/user/getPhonePassword1",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"password": password,
			"phone": phone,
			"code": code
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				if(confirm("添加成功！")) {
					//刷新
					//location.reload();
					window.location.href = "1.0.0denglu.html";
				} else {
					//跳转列表页
					window.location.href = "1.0.2zhaohuimima.html";
				}
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				alert(data.msg);
			}

		},
		error: function() {
			alert("error");
		}

	});
}

function getCode() {
	var phone = $('#phone').val();
	if(phone == '') {
		alert("请输入手机号码！");
		return false;
	}
	$.ajax({
		url: urlcore + "/api/user/getPhoneCode?phone=" + phone+"&type="+1,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var da = data.data;
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				alert(data.msg);
			}
		},
		error: function() {
			alert("error");
		}
	});
}